package com.bdqn.dao;

import java.sql.*;

public class deleteDao {//System.out.println()快捷方法sout+回车
    public static void main(String[] args) {
        Connection con=null;
        ResultSet rs=null;
        PreparedStatement pstmt=null;
            //第一步加载驱动
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //获取连接对象
            con = DriverManager.getConnection("jdbc:mysql://localhost:3306/school?serverTimezone=GMT-8", "root", "123");
            //写SQL语句
            String sql = "DELETE FROM student WHERE studentno=?";
            //执行SQL
            pstmt = con.prepareStatement(sql);
            pstmt.setObject(1,2);
            int count= pstmt.executeUpdate();
            //处理结果集
            if (count > 0) {
                System.out.println("删除成功");

            }else {
                System.out.println("删除失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if (rs!=null){
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (pstmt!=null){
                try {
                    pstmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if (con!=null){
                try {
                    con.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
